﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Agile.Engine.View;
using System.Collections;
using Agile.Engine;
using Agile.Engine.Data;

namespace Fis.Win.Rules
{
    public class UserListViewProvider : ClientViewProvider
    {
        public override System.Collections.Hashtable InitializeViewModel(System.Collections.Hashtable args)
        {
            Hashtable m = new Hashtable();

            m["viewData"] = DataContext.DefaultModel.QueryTable(DataTableName
                , string.Format("FRIGHTS<='{0}'", Fis.Win.Utils.AppSession.IsAdminUser ? "1" : "0"));
            return m;
        }

        public override bool ExecuteUpdate(Hashtable viewModel)
        {
            var param = Fis.Win.Utils.AppSession.CreateServiceParamter(new Hashtable());
            param["Action"] = "Delete";
            param["SID"] = viewModel["SID"];
            var exec = InvokeService(param);

            if (exec)
            {
                var sid = viewModel["SID"].ToString();
                DataContext.DefaultModel.ExecuteNonQuery(
                    string.Format("UPDATE {0} SET FSTATUS=-1  WHERE SID='{1}'", DataTableName, sid));

            }
            return exec;
        }
    }
}
